const Router = require('koa-router')

const { create, update, updateStatus, query, queryMy, statusQueryMy } = require('../controller/project.controller')
const { auth, verifyRole, verifyAdmin } = require('../middleware/auth.middleware')
const { validatort } = require('../middleware/validator.middlewear')
const { formatError } = require('../constant/error.type')

const router = new Router({ prefix: '/project' })

router.post('/', auth, validatort({
    projectName: 'string',
    projectUrl: 'string',
    estimate: 'number',
    empIds: 'array'
}, formatError), create)

router.put('/:id', auth, validatort({
    projectName: 'string',
    projectUrl: 'string',
    estimate: 'number',
    director: 'number',
    empIds: 'array'
}, formatError), update)

router.put('/updateStatus/:id/:status', auth, verifyRole, updateStatus)

router.get('/audit/:status', auth, verifyAdmin, query)

router.get('/my', auth, queryMy)

router.get('/my/:status', auth, statusQueryMy)

module.exports = router